package cn.edu.sjtu.se.dslab.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.edu.sjtu.se.dslab.component.design.DesignPattern;
import cn.edu.sjtu.se.dslab.service.IDesignPatternService;


@Controller
public class DesignPatternController {
	
	@Resource(name="designPatternService")
	IDesignPatternService designPatternService;
	
	@RequestMapping(value="/designPatternList", method = RequestMethod.GET)
	public ModelAndView getDesignPatternList(@RequestParam(value="PageNum",defaultValue="1") int pageNum){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("design_pattern");
		
		List<DesignPattern> dpList = designPatternService.getDesignPatternList();	
		mav.addObject("designPatternList", dpList);
		
		DesignPattern dp = designPatternService.getDesignPatternById(dpList.get(1).getId());
		mav.addObject("designPattern", dp);
		
		return mav;
	}
	
	
	@RequestMapping(value="/design_pattern/{uri}",method = RequestMethod.GET)
	public ModelAndView getDesignPattern(@PathVariable(value="uri") String uri) {	
		ModelAndView mav = new ModelAndView();
		mav.setViewName("design_pattern");
		
		List<DesignPattern> dpList = designPatternService.getDesignPatternList();	
		mav.addObject("designPatternList", dpList);
		
		DesignPattern dp = designPatternService.getDesignPatternByUri(uri);
		mav.addObject("designPattern", dp);
		
		return mav;
	}
	
	@RequestMapping(value="/config_design_pattern",method= RequestMethod.GET)
	public ModelAndView configDesignPattern(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("pattern_config");
		return mav;
	}
	
}
